import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/home'
import $ from 'jquery'

import order from '@/components/salesman/order'   //订单列表
import NewOrder from '@/components/salesman/NewOrder' //新建订单
//后台管理系统
import accountManage from '@/components/backgroundManaSys/accountManage' //用户管理
import departmentManage from '@/components/backgroundManaSys/departmentManage' //部门管理
import flowConfigure from '@/components/backgroundManaSys/flowConfigure' //流程配置
import metadataManage from '@/components/backgroundManaSys/metadataManage' //元数据管理
import roleManage from '@/components/backgroundManaSys/roleManage' //角色管理
import addAccount from '@/components/backgroundManaSys/addAccount' //添加用户
import addOrChangeMeta from '@/components/backgroundManaSys/addOrChangeMeta' //元数据的修改和添加
import functionManage from '@/components/backgroundManaSys/FunctionManage' //功能管理
import loanLimitManage from '@/components/backgroundManaSys/LoanLimitManage' //额度管理
import warningManage from '@/components/backgroundManaSys/WarningManage' //飘红管理
import agencyManage from '@/components/backgroundManaSys/agencymanage'//经销商类别
import addAgency from '@/components/backgroundManaSys/addagency'
//资产保全
import OverdueList from '@/components/AssetProtection/OverdueList'
import UrgeManageTab from '@/components/AssetProtection/UrgeManageTab'
//消息提醒
import message from '@/components/messagelist'
 
Vue.use(Router)
const Login = resolve => require(['@/components/login'], resolve)

let router = new Router({
  routes: [
    {
      path:'/login',
      name:'登录',
      component:Login
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {
          path: '/backgroundManaSys/addAccount',
          component: addAccount,
          name: '新增用户',
        }
      ]
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {
          path: '/backgroundManaSys/addagency',
          component: addAgency,
          name: '新增经销商',
        }
      ]
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {
          path: '/messagelist',
          component: message,
          name: '消息列表',
        }
      ]
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {
          path: '/AssetProtection/UrgeManageTab',
          component: UrgeManageTab,
          name: '催收管理Tab',
        }
      ]
    },
    {
      path: '/',
      name: 'home',
      component: Home,
      //redirect: '/dashboard',
      level:1,
      leaf: true, // 只有一个节点
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {
          path: '/backgroundManaSys/addOrChangeMeta',
          component: addOrChangeMeta,
          name: '元数据管理',
        }
      ]
    },
    {
      path: '/',
      name: '账号管理',
      component: Home,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      level:1,
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/accountManage', component: accountManage, name: '账号管理', menuShow: false}
      ]
    },
    {
      path: '/',
      name: '逾期清单',
      component: Home,
      //redirect: '/dashboard',
      leaf: false, // 只有一个节点
      level:1,
      menuShow: false,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/AssetProtection/OverdueList', component: OverdueList, name: '逾期清单', menuShow: false}
      ]
    },
    {
      path: '/',
      name: '角色管理',
      component: Home,
      level:1,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/roleManage', component: roleManage, name: '角色管理', menuShow: false}
      ]
    },
    {
      path: '/',
      name: '经销商管理',
      component: Home,
      level:1,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/agencymanage', component: agencyManage, name: '经销商管理', menuShow: false}
      ]
    },
    {
      path: '/',
      name: '部门管理',
      component: Home,
      level:1,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/departmentManage', component: departmentManage, name: '部门管理', menuShow: false}
      ]
    },
    {
      path: '/',
      name: '数据管理',
      component: Home,
      level:1,
      //redirect: '/dashboard',
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/metadataManage', component: metadataManage, name: '数据管理', menuShow: false}
      ]
    },
    {
      path: '/',
      name: '功能管理',
      component: Home,
      //redirect: '/dashboard',
      level:1,
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/FunctionManage', component: functionManage, name: '功能管理', menuShow: false},
      ]
    },
    {
      path: '/',
      name: '流程配置',
      component: Home,
      //redirect: '/dashboard',
      level:1,
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/flowConfigure', component: flowConfigure, name: '流程配置', menuShow: false}
      ]
    },
    {
      path: '/',
      name: '额度管理',
      component: Home,
      //redirect: '/dashboard',
      level:1,
      leaf: true, // 只有一个节点
      menuShow: true,
      iconCls: 'iconfont icon-home', // 图标样式class
      children: [
        {path: '/backgroundManaSys/LoanLimitManage', component: loanLimitManage, name: '额度管理', menuShow: false},
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.path.startsWith('/login')) {
    window.sessionStorage.removeItem('access-user')
    next()
  } else {
    let user = JSON.parse(window.sessionStorage.getItem('access-user'))
    if (!user) {
      next({path: '/login'})
    } else {
      next()
    }
  }
})


export default router
